package com.edu.test;

import com.edu.bean.*;
import com.edu.mapper.EmpMapper;
import com.edu.mapper.StudentMapper;
import com.edu.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/*
 * @Author:mx
 * @Date:2025/9/30-14:26:45
 */
public class MyTest02 {

    private SqlSession session;

    @Before
    public void init() throws IOException {
        String path = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(path);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        session = sessionFactory.openSession();
    }

    @Test
    public void test01() {
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = userMapper.selectUserById(1);
        System.out.println(user);
        for (Bill bill : user.getBillList()) {
            System.out.println(bill);
        }
    }

    @Test
    public void test02() {
        UserMapper userMapper = session.getMapper(UserMapper.class);
        for (User user : userMapper.selectAll()) {
            System.out.println(user);
            System.out.println("该用户的订单:");
            for (Bill bill : user.getBillList()) {
                System.out.println(bill);
            }
            System.out.println("----------");
        }
    }

    @Test
    public void test03() {
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = userMapper.selectUserById2(11);
        System.out.println(user);
        System.out.println(user.getBillList());
    }

}
